package L1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * 查验身份证
 */
public class _016 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.valueOf(reader.readLine());
        String[] strings = new String[N];
        for ( int i=0;i<N;i++){
            strings[i] = reader.readLine();
        }
        ArrayList<String > list = new ArrayList<>();
        for (int i=0;i<N;i++){
            if (!isValid(strings[i])){
                list.add(strings[i]);
            }
        }
        if (list.size()>0){
            for (int i=0;i<list.size();i++){
                System.out.println(list.get(i));
            }
        }else
            System.out.println("All passed");
    }

    private static Boolean isValid(String s){
        int[] Q = new int[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
        char[] M = new char[]{'1' ,'0' ,'X' ,'9', '8', '7' ,'6', '5', '4', '3' ,'2'};
        int sum=0;
        for (int i=0;i<17;i++){
            if(s.charAt(i)>'9'||s.charAt(i)<'0'){
                return false;
            }
            sum+=(s.charAt(i)-'0')*Q[i];
        }
        if (s.charAt(17)==M[sum%11]){
            return true;
        }
        return false;
    }
}
